package com.qfedu.stussm.controller;

import com.qfedu.stussm.entity.Course;
import com.qfedu.stussm.service.intf.CourseService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@Controller
@RequestMapping("/api/cou/")
public class CourseController {
    @Autowired
    private CourseService service;
    @PostMapping("save.do")
    public String save(Course course){
        service.add(course);
        return "redirect:/courselist.html";
    }
    @GetMapping("page.do")
    @ResponseBody
    public PageBeanVo page(int page, int limit ,String c_name){
        return service.selectAll(page, limit , c_name);
    }
    @PostMapping("update.do")
    public String update(Course course){
        int update = service.update(course);
        return "courselist.html";
    }
    @PostMapping("del.do")
    public String del(int c_id){
        int del = service.del(c_id);
        return "courselist.html";
    }
    @GetMapping("all.do")
    public R all(){
        return service.all();
    }
    /**
     *生成Excel并下载 */
    @GetMapping("download.do")
    public void download(HttpServletResponse response) throws IOException {
        service.createExcel(response);
    }
    @PostMapping("upload.do")
    @ResponseBody
    public R upload(MultipartFile file) throws IOException {
        return service.uploadExcel(file);
    }

}
